#ifndef BVHJOINT_H
#define BVHJOINT_H

#include <QObject>
#include <qstring.h>
#include <qstringlist.h>
#include <qpointer.h>
#include <qdebug.h>
#include <QMatrix4x4.h>
//#include <qgraphicstranslation3d.h>
//#include <qgraphicsrotation3d.h>
//#include "qglscenenode.h"

#include <iostream>
#include <Eigen/Geometry>

using namespace Eigen;

class BvhJoint : public QObject
{
	Q_OBJECT

public:
	BvhJoint();
	~BvhJoint();
	BvhJoint(const BvhJoint& bj);
	BvhJoint& operator=(const BvhJoint& bj);
	
	QString getName();
	void setName(QString jointName);
	Vector3f getOffset();
	void setOffset(Vector3f vec);
	bool containsChannel(QString chanName);
	QString getChannel(int i);
	int getChannelCount();
	int getTotalChannelCount();
	void addChannel(QString chanName);
	void addPosChannels();
	void addRotChannels();

	QPointer<BvhJoint> getChild(int i);
	int getChildCount();
	void addChild(BvhJoint* joint);
	void addEndSite();

	QPointer<BvhJoint> getParent();
	void setParent(BvhJoint* parentJoint);
	
	void setFromData(QList<double> data);
	void setFromData(QString chanName, double data);
	int getJointCount();
	QList<BvhJoint*> getJointList();

	Matrix3f calcRotMatrixLocal();
	static Matrix3f calcRotMatrixLocal(double x1, double x2, double x3);
	Matrix3f calcRotMatrixGlobal();
	Vector3f calcPosGlobal();
	Vector3f calcGPos(Vector3f pos = Vector3f::Zero());

	Vector3f getPos();
	Vector3f getRot();
	void setPos(Vector3f pos) { m_pos = pos; }
	void setRot(Vector3f rot) { m_rot = rot; }
	QMatrix4x4 calcMatrix();
	QMatrix4x4 calcMatrix(QMatrix4x4 mat);
	//void addTransformationsOne(QGLSceneNode* node);
	//void addTransformations(QGLSceneNode* node, int val=0);
	//void updateTransformations();

private:
	QString m_name;
	Vector3f m_offset;
	QList<QString> m_channelList;
	QList<QPointer<BvhJoint> > m_childList;
	QPointer<BvhJoint> m_parent;
	Vector3f m_pos;
	Vector3f m_rot;
	//QPointer<QGraphicsRotation3D> rotgt[3];
	//QPointer<QGraphicsTranslation3D> trgt;
};

#endif // BVHJOINT_H
